import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
    {
      path: '/',
      component: () => import('../views/Login'),
    },
    {
      path: '/home',
      name: 'home',
      component: () => import('../views/Home'),
      redirect: '/welcome',
      children: [
        {
          // 控制台
          path: '/welcome',
          name: 'welcome',
          component: () => import('../views/Welcome')
        },
        {//菜单列表
          path: '/menus',
          name: 'menus',
          component: () => import('../views/menus/menus')
        }, {
          path: '/role',
          name: 'role',
          component: () => import("../views/role/role")
        }, {
          path: '/roleJurisdiction',
          name: 'roleJurisdiction',
          component: () => import("../views/role/roleJurisdiction")
        }, {
          //管理员列表
          path: '/admin',
          name: 'admin',
          component: () => import("../views/admin/admin")
        }, {
          //用户列表
          path: '/user',
          name: 'user',
          component: () => import("../views/user/user")
        },
        {
          //小说列表
          path: '/novel_list',
          name: 'novel_list',
          component: () => import('../views/Novel_List/List/Novel_List')
        }, {//小说详情
          path: '/novel_details',
          name: 'novel_details',
          component: () => import('../views/Novel_List/List/Novel_Details')

        }, {
          //小说章节
          path: '/novel_diversity',
          name: 'novel_diversity',
          component: () => import('../views/Novel_List/List/novel_diversity')
        }, {
          // 小说频道
          path: '/novel_channelList',
          name: 'novel_channelList',
          component: () => import("../views/Novel_List/novel_channel/channelList")
        }, {
          //小说频道
          path: '/novel_channelBanner',
          name: 'novel_channelBanner',
          component: () => import("../views/Novel_List/novel_channel/channelBanner")
        }, {
          //小说频道
          path: '/novel_channelColumn',
          name: 'novel_channelColumn',
          component: () => import("../views/Novel_List/novel_channel/channelColumn")
        }, {
          //小说频道-小说列表
          path: '/channel_novel_list',
          name: 'channel_novel_list',
          component: () => import("../views/Novel_List/novel_channel/channel_novel_list")
        }, {
          //小说评论
          path: '/novel_comments',
          name: 'novel_comments',
          component: () => import("../views/Novel_List/Novel_Comments")
        }, {
          //小说分类
          path: '/novel_class',
          name: 'novel_class',
          component: () => import("../views/Novel_List/Novel_Classification")
        }, { //第三方列表
          path: '/thirdparty_list',
          name: 'thirdparty_list',
          component: () => import("../views/thirdparty/thirdparty_list")
        }, {
          //第三方设置
          path: '/thirdaprty_set',
          name: 'thirdaprty_set',
          component: () => import("../views/thirdparty/thirdaprty_set")

        },
        //消息列表
        {
          path: '/message_list',
          name: 'message_list',
          component: () => import("../views/Message/message_list")
        },
        {
          //财务统计-充值记录
          path: '/financial_top',
          name: 'financial_top',
          component: () => import("../views/Financial/Financial_Top")
        }, {
          //财务统计-提现记录
          path: '/financial_withdraw',
          name: 'financial_withdraw',
          component: () => import("../views/Financial/Financial_withdraw")
        }, {
          //财务统计-明细
          path: '/particulars',
          name: 'particulars',
          component: () => import("../views/Financial/particulars")
        }, {
          //财务统计-手动充值
          path: '/Manualtopup',
          name: 'Manualtopup',
          component: () => import("../views/Financial/Manualtopup")
        },
        {
          //财务统计-vip
          path: '/vip',
          name: 'vip',
          component: () => import("../views/Financial/vip")
        },
        {
          path: '/representation',
          name: 'representation',
          component: () => import('../views/Financial/representation')
        },
        {
          path: '/separate',
          name: 'separate',
          component: () => import('../views/Financial/separate')
        },
        {
          //邀请奖励-邀请收益
          path: '/InviteEarnings',
          name: 'InviteEarnings',
          component: () => import("../views/Inviterewards/InviteEarnings")
        },
        {
          //邀请奖励-邀请关系
          path: '/InviteRelation',
          name: 'InviteRelation',
          component: () => import("../views/Inviterewards/InviteRelation")
        },
        {
          // 站点设置
          path: '/system_site',
          name: 'system_site',
          component: () => import('../views/System/System_Site')
        },
        {
          // 福利设置
          path: '/system_welfare',
          name: 'system_welfare',
          component: () => import('../views/System/System_Welfare')
        },
        {
          // 广告设置
          path: '/withdraw_set',
          name: 'withdraw_set',
          component: () => import('../views/System/withdraw_set')
        }, {
          //说明设置
          path: '/illustration',
          name: 'illustration',
          component: () => import('../views/illustration/illustration')
        }, {
          //常见问题设置
          path: '/problem',
          name: 'problem',
          component: () => import('../views/System/problem')
        }, {
          path: '/agency',
          name: 'agency',
          component: () => import('../views/agency/agency')
        }, {
          path: '/channels',
          name: 'channels',
          component: () => import('../views/agency/channels')
        }, {
          path: '/representation',
          name: 'representation',
          component: () => import('../views/Financial/representation')
        }, {//广告统计
          path: '/advertising',
          name: 'advertising',
          component: () => import('../views/advertising/advertising')
        },
        //推广管理
        {
          path: '/novel_extension', //小说推广
          name: 'novel_extension',
          component: () => import('../views/extension/novel_extension')
        }, {
          path: '/novel_extensionLink', //小说推广链接
          name: 'novel_extensionLink',
          component: () => import('../views/extension/novel_extensionLink')
        }, {
          path: '/official_extension', //推广文案管理
          name: 'official_extension',
          component: () => import('../views/extension/official_extension')
        },
        //微信消息
        {
          path: '/wxMessage',
          name: 'wxMessage',
          component: () => import('../views/wxSet/wxMessage')
        },
        {
          path: '/message_set',
          name: 'message_set',
          component: () => import('../views/wxSet/message_set')
        }, {
          path: '/wxMenu',
          name: 'wxMenu',
          component: () => import('../views/wxSet/wxMenu')
        }, {
          path: '/automation',
          name: 'automation',
          component: () => import('../views/wxSet/automation')
        }, {
          path: '/follow _sign',
          name: 'follow _sign',
          component: () => import('../views/wxSet/follow _sign')
        }, { //智能推送
          path: '/intellect-push',
          name: 'intellect-push',
          component: () => import('../views/wxSet/intellect-push')
        }, {
          path: '/wx_set',
          name: 'wx_set',
          component: () => import('../views/wxSet/wx_set')
        }, {
          path: '/author-apply',
          name: 'author-apply',
          component: () => import('../views/author/author-apply')
        }, {
          path: '/article-apply',
          name: 'article-apply',
          component: () => import('../views/author/article-apply')
        }, {
          path: '/novel-apply',
          name: 'novel-apply',
          component: () => import('../views/author/novel-apply')
        }, {
          path: '/author-set',
          name: 'author-set',
          component: () => import('../views/author/author-set')
        }, {
          path: '/author-withdraw',
          name: 'author-withdraw',
          component: () => import('../views/author/author-withdraw')
        }
      ]
    },
    {
      path: '/text_extension', //文字文案
      name: 'text_extension',
      component: () => import('../views/extension/text_extension')
    },
    {
      path: '/img_extension',  //图片文案
      name: 'img_extension',
      component: () => import('../views/extension/img_extension')
    },
    {
      path: '/bg_extension',  //背景文案
      name: 'bg_extension',
      component: () => import('../views/extension/bg_extension')
    },
    {
      path: '/404',
      component:
        () => import('../views/404'),
    }
    ,
    {
      path: '*', redirect:
        '/404',
    }
  ]
;

const router = new VueRouter({
  // mode: 'history',
  base: process.env.BASE_URL,
  routes
})

// 路由守卫
router.beforeEach((to, from, next) => {
  if (to.path === '/') {
    next();
    return
  }
  const tokenStr = sessionStorage.getItem('token');
  if (!tokenStr) {
    next('/');
    return;
  }

  next();
});

const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
};

export default router
